import path from 'path';
import { fileURLToPath } from 'url';

const getDirname = (url) => {
  return path.dirname(fileURLToPath(new URL(url)));
};

import imageUtil from './imageUtil.js';
import screenUtil from './screenUtil.js';
import { screen, imageResource } from '@nut-tree/nut-js';
import '@nut-tree/template-matcher';

const test = async function () {
  screen.config.resourceDirectory = './src/assets';
  const region = await screen.find(imageResource('btn-1-190x80.png'), { confidence: 0.9 });
  screen.highlight(region);
  console.log(region);
  
  const currentDir = getDirname(import.meta.url);
  const base64 = await imageUtil.imageToBase64(
    path.resolve(currentDir, './assets/btn-1-190x80.png')
  );
  const result = await screenUtil.find(base64);
  console.log('result', result);
};

test();